package com.xlj.function;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by user on 17/6/21.
 */
public class MapperTest {

    public static <V, M> List<M> map(List<V> list, Mapper<V, M> mapper) {
        List<M> mapped = new ArrayList<M>(list.size()); // (4)
        for (V v : list) {
            mapped.add(mapper.map(v)); // (5)
        }
        return mapped; // (6)
    }

    private void eachList(List<Integer> list, final Action<Integer> action){
        list.forEach(i->action.action(i));
    }

    @Test
    public void test(){
        List<Integer> list= Arrays.asList(1,2,3,4,5,6);
        eachList(list,System.out::println);
    }
}
